<?php
namespace App\Http\Controllers\Crontab;
use App\Http\Controllers\Controller;
use App\Models\ActivityModel;

class CtontabController extends Controller{
    public function modiActivityStatus(){
        $dt = time();

        // 获取活动列表
        $activityList = ActivityModel::where('isshow',1)->get();
        if(!empty($activityList)){
            foreach($activityList as $atm=>$ast){
                $data['modi_date'] = date('Y-m-d H:i:s');
                if($dt >= strtotime($ast->start_date) && $dt <= strtotime($ast->end_date)){
                    $data['status'] = 1;
                    $res = ActivityModel::where('id',$ast->id)->update($data);
                    if($res){
                        $str = '活动ID：'.$ast->id.',活动名称为：'.$ast->name.'状态更新为已经开始。';
                        file_put_contents('/tmp/'.date('Y-m-d').'_activity_status_modi.log',$str,
                                FILE_APPEND);
                    }

                }elseif($dt > strtotime($ast->end_date)){
                    $data['status'] = 0;
                    $res = ActivityModel::where('id',$ast->id)->update($data);
                    if($res){
                        $str = '活动ID：'.$ast->id.',活动名称为：'.$ast->name.'状态更新为已结束。';
                        file_put_contents('/tmp/'.date('Y-m-d').'_activity_status_modi.log',$str,
                            FILE_APPEND);
                    }
                }else{
                    $str = '暂无活动状态需要更新';
                    file_put_contents('/tmp/'.date('Y-m-d').'_activity_status_modi.log',$str,
                        FILE_APPEND);
                }


            }
        }
    }
}